package com.recsmile.sgs.client.listener;

import java.util.Set;

import com.recsmile.sgs.client.card.equips.Equipment;
import com.recsmile.sgs.client.card.equips.Equipment.EquipmentType;
import com.recsmile.sgs.client.commonds.sync.SyncDisposalAreaRefreshGameUIClientCommand;
import com.recsmile.sgs.client.commonds.sync.SyncEquipGameUIClientCommand;
import com.recsmile.sgs.client.commonds.sync.SyncUnequipGameUIClientCommand;
import com.recsmile.sgs.client.entity.Deck;
import com.recsmile.sgs.client.entity.GameRoom;
import com.recsmile.sgs.client.entity.PlayerComplete;
import com.recsmile.sgs.client.util.SyncCommandsUtil;

public class ServerInGameEquipmentListener extends ServerInGamePlayerListener implements EquipmentListener {
	
	private final Deck deck;
	private final PlayerComplete player;
	
	public ServerInGameEquipmentListener(PlayerComplete player, Set<String> allNames, GameRoom room) {
		super(player.getName(), allNames, room);
		this.player = player;
		this.deck = room.getGame().getDeck();
	}
	
	@Override
	public void onEquipped(Equipment equipment) {
		room.sendCommandToPlayers(
			SyncCommandsUtil.generateMapForSameCommand(
				name, 
				otherNames, 
				new SyncEquipGameUIClientCommand(name, equipment)
			)
		);
	}

	@Override
	public void onUnequipped(EquipmentType type) {
		deck.discard(player.getEquipment(type));
		room.sendCommandToPlayers(
			SyncCommandsUtil.generateMapForSameCommand(
				name, 
				otherNames, 
				new SyncUnequipGameUIClientCommand(name, type)
			)	
		);
		room.sendCommandToPlayers(
			SyncCommandsUtil.generateMapForSameCommand(
				name, 
				otherNames, 
				new SyncDisposalAreaRefreshGameUIClientCommand()
			)
		);
	}

}
